<template>
  <view class="task-item">
    <view class="col-t">
      <view class="col-l">
        <view class="task-name">
          {{ task.title }}
        </view>
        <view class="task-desc">
          {{ task.description }}
        </view>
      </view>
      <view class="col-r" :class="task.isSystem && 'active'">
        {{ task.isSystem ? '系统' : '自定义' }}
      </view>
    </view>
    <view class="col-b" @click="$emit('more')">
      <view class="col-l" :class="childName && 'active'">
        {{ childName || '未生效' }}
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import type { ITask } from '@/api/task'
import { useChildStore } from '@/store/child'

// #region Props
const props = defineProps<{ task: ITask }>()
// #endregion
// #region Emits
defineEmits(['more'])
// #endregion
// #region Hooks
const { childMap } = useChildStore()
// #endregion
// #region Computed
const childName = computed(() => {
  return props.task.isSystem ? '系统' : props.task.children?.map(item => childMap.get(item)).join('、')
})
// #endregion
// #region Watch
// #endregion
// #region Event
// #endregion
// #region Function
// #endregion
// #region Life Cycle
// #endregion
// #region Expose
// #endregion
</script>

<style lang="scss" scoped>
.task-item {
  background: var(--card-border-color);
  border-radius: 16px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--card-border-gary-color);
  box-sizing: border-box;
  padding: 10px;
  .col-t {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    .col-r {
      font-size: 12px;
      width: 50px;
      height: 20px;
      border-radius: 20px;
      color: rgba(0, 0, 0, 0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--main-light-color);
      color: var(--card-border-color);
      &.active {
        background: var(--light-color);
      }
    }
  }
  .col-b {
    background: var(--bg-color);
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    padding: 0 10px;
    font-size: 14px;
    color: var(--text-color);
    position: relative;
    &::after {
      content: '';
      display: flex;
      background: url('https://mp-faaaa8a0-2641-45b8-8dbc-bcb0d1463eb4.cdn.bspapp.com/app/icon-more-gary.png') no-repeat;
      background-size: cover;
      width: 24px;
      height: 24px;
      position: absolute;
      right: 0;
    }
    .col-l {
      color: rgba(0, 0, 0, 0.5);
      &.active {
        color: var(--text-color);
      }
    }
  }
  .col-l {
    flex: 1 0 auto;
    width: 50%;
    display: flex;
    flex-direction: column;
    gap: 5px;
    .task-name {
      font-size: 16px;
      color: var(--main-light-color);
    }
    .task-desc {
      font-size: 14px;
      color: rgba(0, 0, 0, 0.5);
    }
  }
}
</style>
